Produced by Araxis Merge on 2023-03-13 03:00:43 +0000. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | Porto v4.0.4/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/Filter | Attribute.php | 2022-04-22 07:34:10 +0000 |
| 2 | Porto v4.0.5/Porto Theme/app/code/Mageplaza/LayeredNavigation/Model/Layer/Filter | Attribute.php | 2022-12-08 01:34:28 +0000 |
| Description | Between Files 1 and 2 | |
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 1 | 382 |
| Changed | 0 | 0 |
| Inserted | 0 | 0 |
| Removed | 0 | 0 |
| Whitespace | Consecutive whitespace is treated as a single space |
|---|---|
| Character case | Differences in character case are significant |
| Line endings | Differences in line endings (CR and LF characters) are ignored |
| CR/LF characters | Not shown in the comparison detail |
| Active line-pairing rules |
No regular expressions were active.
| 1 | <?php | 1 | <?php | |||
| 2 | /** | 2 | /** | |||
| 3 | * Mageplaza | 3 | * Mageplaza | |||
| 4 | * | 4 | * | |||
| 5 | * NOTICE OF LICENSE | 5 | * NOTICE OF LICENSE | |||
| 6 | * | 6 | * | |||
| 7 | * This source file is subject to the Mageplaza.com license that is | 7 | * This source file is subject to the Mageplaza.com license that is | |||
| 8 | * available through the world-wide-web at this URL: | 8 | * available through the world-wide-web at this URL: | |||
| 9 | * https://www.mageplaza.com/LICENSE.txt | 9 | * https://www.mageplaza.com/LICENSE.txt | |||
| 10 | * | 10 | * | |||
| 11 | * DISCLAIMER | 11 | * DISCLAIMER | |||
| 12 | * | 12 | * | |||
| 13 | * Do not edit or add to this file if you wish to upgrade this extension to newer | 13 | * Do not edit or add to this file if you wish to upgrade this extension to newer | |||
| 14 | * version in the future. | 14 | * version in the future. | |||
| 15 | * | 15 | * | |||
| 16 | * @category Mageplaza | 16 | * @category Mageplaza | |||
| 17 | * @package Mageplaza_LayeredNavigation | 17 | * @package Mageplaza_LayeredNavigation | |||
| 18 | * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | 18 | * @copyright Copyright (c) Mageplaza (https://www.mageplaza.com/) | |||
| 19 | * @license https://www.mageplaza.com/LICENSE.txt | 19 | * @license https://www.mageplaza.com/LICENSE.txt | |||
| 20 | */ | 20 | */ | |||
| 21 | 21 | |||||
| 22 | namespace Mageplaza\LayeredNavigation\Model\Layer\Filter; | 22 | namespace Mageplaza\LayeredNavigation\Model\Layer\Filter; | |||
| 23 | 23 | |||||
| 24 | use Magento\Catalog\Model\Layer as LayerCatalog; | 24 | use Magento\Catalog\Model\Layer as LayerCatalog; | |||
| 25 | use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; | 25 | use Magento\Catalog\Model\Layer\Filter\Item\DataBuilder; | |||
| 26 | use Magento\Catalog\Model\Layer\Filter\ItemFactory; | 26 | use Magento\Catalog\Model\Layer\Filter\ItemFactory; | |||
| 27 | use Magento\CatalogSearch\Model\Layer\Filter\Attribute as AbstractFilter; | 27 | use Magento\CatalogSearch\Model\Layer\Filter\Attribute as AbstractFilter; | |||
| 28 | use Magento\Framework\App\RequestInterface; | 28 | use Magento\Framework\App\RequestInterface; | |||
| 29 | use Magento\Framework\Filter\StripTags; | 29 | use Magento\Framework\Filter\StripTags; | |||
| 30 | use Magento\Store\Model\StoreManagerInterface; | 30 | use Magento\Store\Model\StoreManagerInterface; | |||
| 31 | use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper; | 31 | use Mageplaza\LayeredNavigation\Helper\Data as LayerHelper; | |||
| 32 | use Mageplaza\LayeredNavigation\Model\ResourceModel\Fulltext\Collection; | 32 | use Mageplaza\LayeredNavigation\Model\ResourceModel\Fulltext\Collection; | |||
| 33 | 33 | |||||
| 34 | /** | 34 | /** | |||
| 35 | * Class Attribute | 35 | * Class Attribute | |||
| 36 | * @package Mageplaza\LayeredNavigation\Model\Layer\Filter | 36 | * @package Mageplaza\LayeredNavigation\Model\Layer\Filter | |||
| 37 | */ | 37 | */ | |||
| 38 | class Attribute extends AbstractFilter | 38 | class Attribute extends AbstractFilter | |||
| 39 | { | 39 | { | |||
| 40 | /** @var LayerHelper */ | 40 | /** @var LayerHelper */ | |||
| 41 | protected $_moduleHelper; | 41 | protected $_moduleHelper; | |||
| 42 | 42 | |||||
| 43 | /** @var bool Is Filterable Flag */ | 43 | /** @var bool Is Filterable Flag */ | |||
| 44 | protected $_isFilter = true; | 44 | protected $_isFilter = true; | |||
| 45 | 45 | |||||
| 46 | /** @var StripTags */ | 46 | /** @var StripTags */ | |||
| 47 | private $tagFilter; | 47 | private $tagFilter; | |||
| 48 | 48 | |||||
| 49 | /** | 49 | /** | |||
| 50 | * Attribute constructor. | 50 | * Attribute constructor. | |||
| 51 | * | 51 | * | |||
| 52 | * @param ItemFactory $filterItemFactory | 52 | * @param ItemFactory $filterItemFactory | |||
| 53 | * @param StoreManagerInterface $storeManager | 53 | * @param StoreManagerInterface $storeManager | |||
| 54 | * @param LayerCatalog $layer | 54 | * @param LayerCatalog $layer | |||
| 55 | * @param DataBuilder $itemDataBuilder | 55 | * @param DataBuilder $itemDataBuilder | |||
| 56 | * @param StripTags $tagFilter | 56 | * @param StripTags $tagFilter | |||
| 57 | * @param LayerHelper $moduleHelper | 57 | * @param LayerHelper $moduleHelper | |||
| 58 | * @param array $data | 58 | * @param array $data | |||
| 59 | */ | 59 | */ | |||
| 60 | public function __construct( | 60 | public function __construct( | |||
| 61 | ItemFactory $filterItemFactory, | 61 | ItemFactory $filterItemFactory, | |||
| 62 | StoreManagerInterface $storeManager, | 62 | StoreManagerInterface $storeManager, | |||
| 63 | LayerCatalog $layer, | 63 | LayerCatalog $layer, | |||
| 64 | DataBuilder $itemDataBuilder, | 64 | DataBuilder $itemDataBuilder, | |||
| 65 | StripTags $tagFilter, | 65 | StripTags $tagFilter, | |||
| 66 | LayerHelper $moduleHelper, | 66 | LayerHelper $moduleHelper, | |||
| 67 | array $data = [] | 67 | array $data = [] | |||
| 68 | ) { | 68 | ) { | |||
| 69 | $this->tagFilter = $tagFilter; | 69 | $this->tagFilter = $tagFilter; | |||
| 70 | $this->_moduleHelper = $moduleHelper; | 70 | $this->_moduleHelper = $moduleHelper; | |||
| 71 | 71 | |||||
| 72 | parent::__construct( | 72 | parent::__construct( | |||
| 73 | $filterItemFactory, | 73 | $filterItemFactory, | |||
| 74 | $storeManager, | 74 | $storeManager, | |||
| 75 | $layer, | 75 | $layer, | |||
| 76 | $itemDataBuilder, | 76 | $itemDataBuilder, | |||
| 77 | $tagFilter, | 77 | $tagFilter, | |||
| 78 | $data | 78 | $data | |||
| 79 | ); | 79 | ); | |||
| 80 | } | 80 | } | |||
| 81 | 81 | |||||
| 82 | /** | 82 | /** | |||
| 83 | * @inheritdoc | 83 | * @inheritdoc | |||
| 84 | */ | 84 | */ | |||
| 85 | public function apply(RequestInterface $request) | 85 | public function apply(RequestInterface $request) | |||
| 86 | { | 86 | { | |||
| 87 | if (!$this->_moduleHelper->isEnabled()) { | 87 | if (!$this->_moduleHelper->isEnabled()) { | |||
| 88 | return parent::apply($request); | 88 | return parent::apply($request); | |||
| 89 | } | 89 | } | |||
| 90 | 90 | |||||
| 91 | $attributeValue = $request->getParam($this->_requestVar); | 91 | $attributeValue = $request->getParam($this->_requestVar); | |||
| 92 | $attribute = $this->getAttributeModel(); | 92 | $attribute = $this->getAttributeModel(); | |||
| 93 | 93 | |||||
| 94 | if (!($attributeValue === '0' && $attribute->getFrontendInput() === 'boolean')) { | 94 | if (!($attributeValue === '0' && $attribute->getFrontendInput() === 'boolean')) { | |||
| 95 | if (empty($attributeValue)) { | 95 | if (empty($attributeValue)) { | |||
| 96 | $this->_isFilter = false; | 96 | $this->_isFilter = false; | |||
| 97 | return $this; | 97 | return $this; | |||
| 98 | } | 98 | } | |||
| 99 | } | 99 | } | |||
| 100 | 100 | |||||
| 101 | $attributeValue = explode(',', $attributeValue); | 101 | $attributeValue = explode(',', $attributeValue); | |||
| 102 | 102 | |||||
| 103 | $attribute = $this->getAttributeModel(); | 103 | $attribute = $this->getAttributeModel(); | |||
| 104 | /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */ | 104 | /** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */ | |||
| 105 | $productCollection = $this->getLayer() | 105 | $productCollection = $this->getLayer() | |||
| 106 | ->getProductCollection(); | 106 | ->getProductCollection(); | |||
| 107 | if (count($attributeValue) > 1) { | 107 | if (count($attributeValue) > 1) { | |||
| 108 | $productCollection->addFieldToFilter($attribute->getAttributeCode(), ['in' => $attributeValue]); | 108 | $productCollection->addFieldToFilter($attribute->getAttributeCode(), ['in' => $attributeValue]); | |||
| 109 | } else { | 109 | } else { | |||
| 110 | $productCollection->addFieldToFilter($attribute->getAttributeCode(), $attributeValue[0]); | 110 | $productCollection->addFieldToFilter($attribute->getAttributeCode(), $attributeValue[0]); | |||
| 111 | } | 111 | } | |||
| 112 | 112 | |||||
| 113 | $state = $this->getLayer()->getState(); | 113 | $state = $this->getLayer()->getState(); | |||
| 114 | foreach ($attributeValue as $value) { | 114 | foreach ($attributeValue as $value) { | |||
| 115 | $label = $this->getOptionText($value); | 115 | $label = $this->getOptionText($value); | |||
| 116 | $state->addFilter($this->_createItem($label, $value)); | 116 | $state->addFilter($this->_createItem($label, $value)); | |||
| 117 | } | 117 | } | |||
| 118 | 118 | |||||
| 119 | return $this; | 119 | return $this; | |||
| 120 | } | 120 | } | |||
| 121 | 121 | |||||
| 122 | /** | 122 | /** | |||
| 123 | * @inheritdoc | 123 | * @inheritdoc | |||
| 124 | */ | 124 | */ | |||
| 125 | protected function _getItemsData() | 125 | protected function _getItemsData() | |||
| 126 | { | 126 | { | |||
| 127 | if (!$this->_moduleHelper->isEnabled()) { | 127 | if (!$this->_moduleHelper->isEnabled()) { | |||
| 128 | return parent::_getItemsData(); | 128 | return parent::_getItemsData(); | |||
| 129 | } | 129 | } | |||
| 130 | 130 | |||||
| 131 | $attribute = $this->getAttributeModel(); | 131 | $attribute = $this->getAttributeModel(); | |||
| 132 | 132 | |||||
| 133 | /** @var Collection $productCollection */ | 133 | /** @var Collection $productCollection */ | |||
| 134 | $productCollection = $this->getLayer()->getProductCollection(); | 134 | $productCollection = $this->getLayer()->getProductCollection(); | |||
| 135 | 135 | |||||
| 136 | if ($this->_isFilter) { | 136 | if ($this->_isFilter) { | |||
| 137 | $productCollection = $productCollection->getCollectionClone() | 137 | $productCollection = $productCollection->getCollectionClone() | |||
| 138 | ->removeAttributeSearch($attribute->getAttributeCode()); | 138 | ->removeAttributeSearch($attribute->getAttributeCode()); | |||
| 139 | } | 139 | } | |||
| 140 | 140 | |||||
| 141 | $optionsFacetedData = $productCollection->getFacetedData($attribute->getAttributeCode()); | 141 | $optionsFacetedData = $productCollection->getFacetedData($attribute->getAttributeCode()); | |||
| 142 | 142 | |||||
| 143 | if (count($optionsFacetedData) === 0 | 143 | if (count($optionsFacetedData) === 0 | |||
| 144 | && $this->getAttributeIsFilterable($attribute) !== static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS | 144 | && $this->getAttributeIsFilterable($attribute) !== static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS | |||
| 145 | ) { | 145 | ) { | |||
| 146 | return $this->itemDataBuilder->build(); | 146 | return $this->itemDataBuilder->build(); | |||
| 147 | } | 147 | } | |||
| 148 | 148 | |||||
| 149 | $productSize = $productCollection->getSize(); | 149 | $productSize = $productCollection->getSize(); | |||
| 150 | $itemData = []; | 150 | $itemData = []; | |||
| 151 | $checkCount = false; | 151 | $checkCount = false; | |||
| 152 | 152 | |||||
| 153 | $options = $attribute->getFrontend()->getSelectOptions(); | 153 | $options = $attribute->getFrontend()->getSelectOptions(); | |||
| 154 | foreach ($options as $option) { | 154 | foreach ($options as $option) { | |||
| 155 | if (empty($option['value'])) { | 155 | if (empty($option['value'])) { | |||
| 156 | continue; | 156 | continue; | |||
| 157 | } | 157 | } | |||
| 158 | 158 | |||||
| 159 | $value = $option['value']; | 159 | $value = $option['value']; | |||
| 160 | 160 | |||||
| 161 | $count = isset($optionsFacetedData[$value]['count']) | 161 | $count = isset($optionsFacetedData[$value]['count']) | |||
| 162 | ? (int)$optionsFacetedData[$value]['count'] | 162 | ? (int)$optionsFacetedData[$value]['count'] | |||
| 163 | : 0; | 163 | : 0; | |||
| 164 | 164 | |||||
| 165 | // Check filter type | 165 | // Check filter type | |||
| 166 | if ($this->getAttributeIsFilterable($attribute) === static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS | 166 | if ($this->getAttributeIsFilterable($attribute) === static::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS | |||
| 167 | && (!$this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $productSize)) | 167 | && (!$this->_moduleHelper->getFilterModel()->isOptionReducesResults($this, $count, $productSize)) | |||
| 168 | ) { | 168 | ) { | |||
| 169 | continue; | 169 | continue; | |||
| 170 | } | 170 | } | |||
| 171 | 171 | |||||
| 172 | if ($count > 0) { | 172 | if ($count > 0) { | |||
| 173 | $checkCount = true; | 173 | $checkCount = true; | |||
| 174 | } | 174 | } | |||
| 175 | 175 | |||||
| 176 | $itemData[] = [ | 176 | $itemData[] = [ | |||
| 177 | 'label' => $this->tagFilter->filter($option['label']), | 177 | 'label' => $this->tagFilter->filter($option['label']), | |||
| 178 | 'value' => $value, | 178 | 'value' => $value, | |||
| 179 | 'count' => $count | 179 | 'count' => $count | |||
| 180 | ]; | 180 | ]; | |||
| 181 | } | 181 | } | |||
| 182 | 182 | |||||
| 183 | if ($checkCount) { | 183 | if ($checkCount) { | |||
| 184 | foreach ($itemData as $item) { | 184 | foreach ($itemData as $item) { | |||
| 185 | $this->itemDataBuilder->addItemData($item['label'], $item['value'], $item['count']); | 185 | $this->itemDataBuilder->addItemData($item['label'], $item['value'], $item['count']); | |||
| 186 | } | 186 | } | |||
| 187 | } | 187 | } | |||
| 188 | 188 | |||||
| 189 | return $this->itemDataBuilder->build(); | 189 | return $this->itemDataBuilder->build(); | |||
| 190 | } | 190 | } | |||
| 191 | } | 191 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993–2019 Araxis Ltd (www.araxis.com). All rights reserved.